package DisruptorTest;

import com.lmax.disruptor.RingBuffer;

// 不建议使用
@Deprecated
public class MessageEventProducer {
    private final RingBuffer<MessageEvent> ringBuffer;

    public MessageEventProducer(RingBuffer<MessageEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void onData(String message) {
        long sequence = ringBuffer.next();  // Grab the next sequence
        try {
            MessageEvent event = ringBuffer.get(sequence); // Get the entry in the Disruptor
            // for the sequence
            event.setValue(message);
        } finally {
            ringBuffer.publish(sequence);
        }
    }
}
